/*
 * Copyright © 2010 SenseForce.com.
 * The Software shall be used for Good, not Evil.
 */

package com.senseforce.classes;

import javax.microedition.lcdui.*;
import com.senseforce.midlets.ShortMessage;

/**
 *
 * @author jcccn
 * @site http://www.senseforce.com/
 */
public class MessageSendForm extends Form implements CommandListener {
	
	private ShortMessage midlet;
	private Command backCommand = new Command("Back", Command.BACK, 0);
	private Command okCommand = new Command("OK", Command.SCREEN, 0);
	
	private TextField phoneNumberTextField = new TextField(null, null, 20, TextField.PHONENUMBER);
	
	public MessageSendForm(String title, ShortMessage midlet) {
		super(title);
		this.midlet = midlet;
		
		phoneNumberTextField.setLayout(Item.LAYOUT_LEFT);
		//phoneNumberTextField.setPreferredWidth(getWidth());
		append(phoneNumberTextField);

                setCommandListener(this);
                addCommand(backCommand);
                addCommand(okCommand);
	}

        public void clearPhoneNumber() {
            phoneNumberTextField.setString(null);
        }
	
	public void commandAction(Command c, Displayable d) {
		if (c == backCommand) {
			midlet.changeFormWithType(MessageConfig.FORMTYPE_EDIT);
		}
		else if (c == okCommand) {
			MessageConfig.PHONE_NUMBER = phoneNumberTextField.getString();
			System.out.println("Message sent successfully!");
			System.out.println("sms to: " + MessageConfig.PHONE_NUMBER);
			System.out.println("content: " + MessageConfig.MESSAGE);
			
			midlet.changeFormWithType(MessageConfig.FORMTYPE_ALERT);
		}
	}
}
